package sseGameApps.controller.mdkbr.main;

import java.util.HashMap;
import java.util.Map;

import org.slim3.controller.Navigation;

import sseGameApps.controller.JsonController;
import sseGameApps.model.mdkbr.MdKanji;
import sseGameApps.service.mdkbr.MdKanjiService;

public class MdSummonSelKanjiController extends JsonController {

    private MdKanjiService serviceMdKanji = new MdKanjiService();
    @Override
    public Navigation run() throws Exception {

        Map<String, String> data = new HashMap<String, String>();

        if (("".equals(asString("summonTxt1")) && "".equals(asString("summonTxt2")) && "".equals(asString("summonTxt3"))) || "".equals(asString("userId"))){
            data.put("summonedTxt1", "");
            data.put("summonedTxt2", "");
            data.put("summonedTxt3", "");
            data.put("barPoint1", "");
            data.put("barPoint2", "");
            data.put("barPoint3", "");
            data.put("attackPoint1", "");
            data.put("attackPoint2", "");
            data.put("attackPoint3", "");
            data.put("kanjiType1", "");
            data.put("kanjiType2", "");
            data.put("kanjiType3", "");
            this.toJson(data);
            return null;
        }

        MdKanji mdKanji1 = new MdKanji();
        MdKanji mdKanji2 = new MdKanji();
        MdKanji mdKanji3 = new MdKanji();

        if (!"".equals(asString("summonTxt1"))){
            mdKanji1 = serviceMdKanji.registKanjiSel(asString("summonTxt1"), asString("summonLvl1"), asString("userId"));

            if (mdKanji1 == null){
                data.put("summonedTxt1", "");
                data.put("barPoint1", "");
                data.put("attackPoint1", "");
                data.put("kanjiType1", "");
            }else{
                data.put("summonedTxt1", mdKanji1.getMojiText());
                data.put("barPoint1", mdKanji1.getBarPoint().toString());
                data.put("attackPoint1", mdKanji1.getAttackPoint().toString());
                data.put("kanjiType1", mdKanji1.getKanjiTypeText());
            }
        }
        if (!"".equals(asString("summonTxt2"))){
//            mdKanji2 = serviceMdKanji.registKanji(asString("summonTxt2"), asString("userId"));
            mdKanji2 = serviceMdKanji.registKanjiSel(asString("summonTxt2"), asString("summonLvl2"), asString("userId"));

            if (mdKanji2 == null){
                data.put("summonedTxt2", "");
                data.put("barPoint2", "");
                data.put("attackPoint2", "");
                data.put("kanjiType2", "");
            }else{
                data.put("summonedTxt2", mdKanji2.getMojiText());
                data.put("barPoint2", mdKanji2.getBarPoint().toString());
                data.put("attackPoint2", mdKanji2.getAttackPoint().toString());
                data.put("kanjiType2", mdKanji2.getKanjiTypeText());
            }
        }
        if (!"".equals(asString("summonTxt3"))){
//            mdKanji3 = serviceMdKanji.registKanji(asString("summonTxt3"), asString("userId"));
            mdKanji3 = serviceMdKanji.registKanjiSel(asString("summonTxt3"), asString("summonLvl3"), asString("userId"));

            if (mdKanji3 == null){
                data.put("summonedTxt3", "");
                data.put("barPoint3", "");
                data.put("attackPoint3", "");
                data.put("kanjiType3", "");
            }else{
                data.put("summonedTxt3", mdKanji3.getMojiText());
                data.put("barPoint3", mdKanji3.getBarPoint().toString());
                data.put("attackPoint3", mdKanji3.getAttackPoint().toString());
                data.put("kanjiType3", mdKanji3.getKanjiTypeText());
            }
        }

        this.toJson(data);

        return null;
    }
}
